﻿//-----------SqlAccess.cs
//--------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess
{
    public class SqlAccess
    {
        private static string _connectionString=@"Data Source=.\SQLEXPRESS;Initial Catalog=QLHS;Integrated Security=True";
        public static String ConnectionString
        {
            get
            {
                return _connectionString;
            }
            set
            {
                _connectionString = value;
            }
        }
        public static String ReadConnectionString(String file)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(file);
                XmlElement root = doc.DocumentElement;
                String connectionString = root.InnerText;
                return connectionString;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataTable ExecuteQuery(string sql)
        {
            SqlConnection cn = new SqlConnection(ConnectionString);
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = sql;

            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataTable kq=new DataTable();
            adp.Fill(kq);
            return kq;
        }
    }
}
